import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;

public class HockeyPoolDriver {

	public static void main(String[] args) {
		HockeyPlayer daniel = new HockeyPlayer("Daniel", "Sedin");

		daniel.addGoal();

		int totalPoints = daniel.getTotalPoints();

		HockeyPlayer someone = daniel;

		someone.addGoal();

		System.out.println(daniel.getGoals());

		HockeyPlayer alex = new HockeyPlayer("Alex", "Burrows");

		alex.addGoal();
		alex.addGoal();
		alex.addGoal();

		List<HockeyPlayer> canucks = new ArrayList<HockeyPlayer>();

		canucks.add(daniel);
		canucks.add(alex);
		canucks.add(new HockeyPlayer("Henrik", "Sedin"));

		daniel = null;

		HockeyPlayer who = canucks.get(0);

		System.out.println(who.getFirstName());

		System.out.println("Team is ");

		for (int i = 0; i < canucks.size(); i++) {
			HockeyPlayer aPlayer = canucks.get(i);
			System.out.println(aPlayer.getFirstName());
		}

		System.out.println("Team (iterate) is ");

		Iterator<HockeyPlayer> secretary = canucks.iterator();

		while (secretary.hasNext()) {
			HockeyPlayer aPlayer = secretary.next();
			System.out.println(aPlayer.getFirstName());
		}

		System.out.println("Team (for each) is ");

		for (HockeyPlayer aPlayer : canucks) {
			System.out.println(aPlayer.getFirstName());
		}

		// Locate Daniel Sedin the difficult way

		HockeyPlayer foundPlayer = null;

		for (HockeyPlayer aPlayer : canucks) {
			String firstName = aPlayer.getFirstName();
			String lastName = aPlayer.getLastName();

			if (firstName.equals("Daniel") && lastName.equals("Sedin")) {
				foundPlayer = aPlayer;
				break;
			}
		}

		for (HockeyPlayer aPlayer : canucks) {
			String firstName = aPlayer.getFirstName();
			String lastName = aPlayer.getLastName();

			if (!firstName.equals("Daniel")) {
				continue;
			}

			if (!lastName.equals("Sedin")) {
				continue;
			}

			foundPlayer = aPlayer;
			break;
		}

		System.out.println(foundPlayer.getFirstName() + " "
				+ foundPlayer.getGoals());

		HockeyPlayer twelveYearOld = new HockeyPlayer("Daniel", "Sedin");

		for (HockeyPlayer aPlayer : canucks) {
			if (twelveYearOld.isAMatchFor(aPlayer)) {
				foundPlayer = aPlayer;
				break;
			}
		}

		int positionOnList = canucks.indexOf(twelveYearOld);

		foundPlayer = canucks.get(positionOnList);

		// find the biggest/best player

		HockeyPlayer biggestSoFar = canucks.get(0);

		for (int i = 1; i < canucks.size(); i++) {
			HockeyPlayer nextOne = canucks.get(i);

			int biggestSoFarTotalPoints = biggestSoFar.getTotalPoints();
			int nextOneTotalPoints = nextOne.getTotalPoints();

			if (nextOneTotalPoints > biggestSoFarTotalPoints) {
				biggestSoFar = nextOne;
			}
		}

		System.out.println("Biggest player is " + biggestSoFar.getFirstName());

		// find the biggest/best player with a player doing the work

		biggestSoFar = canucks.get(0);

		for (int i = 1; i < canucks.size(); i++) {
			HockeyPlayer nextOne = canucks.get(i);

			if (nextOne.compareTo(biggestSoFar) > 0) {
				biggestSoFar = nextOne;
			}
		}

		System.out.println("Biggest player is " + biggestSoFar.getFirstName());

		HockeyPlayer biggest = Collections.max(canucks);

		Collections.sort(canucks);
		Collections.reverse(canucks);

		canucks.remove(new HockeyPlayer("Alex", "Burrows"));

		// copy a list

		List<HockeyPlayer> coachList = new ArrayList<HockeyPlayer>();

		for (HockeyPlayer someOne : canucks) {
			coachList.add(someOne);
		}

		coachList.remove(new HockeyPlayer("Daniel", "Sedin"));

		List<HockeyPlayer> myTeam = new ArrayList<HockeyPlayer>(canucks);

	}
}